package cn.com.doone.common.uc.infrastructure.shiro;

import org.apache.shiro.realm.jdbc.JdbcRealm;
import org.springframework.beans.factory.InitializingBean;

public class DooneJdbcRealm extends JdbcRealm implements InitializingBean {
	
	public static final String AUTHENTICATION_QUERY = "SELECT PASSWORD FROM user_info WHERE STATUS = 1 AND USER_ACCOUNT = ?";

    public static final String USER_ROLES_QUERY = "select r.role_name from user_roles ur,user_info u,roles r  where ur.users_id = u.USER_INFO_ID and ur.roles_id = r.id and u.USER_ACCOUNT = ?";

    public static final String PERMISSIONS_QUERY = "select rp.permission from roles_permissions rp,roles r where r.id = rp.roles_id and r.role_name = ?";

    public DooneJdbcRealm() {
        super();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        // override
        setAuthenticationQuery(AUTHENTICATION_QUERY);
        setUserRolesQuery(USER_ROLES_QUERY);
        setPermissionsQuery(PERMISSIONS_QUERY);
    }

}
